package client.comm.baoding.fragment

import android.view.View
import client.comm.commlib.base.BaseFragment
import client.comm.commlib.toast.toast
import client.comm.commlib.widget.EmptyLayout
import client.comm.baoding.R
import client.comm.baoding.databinding.FragmentSetxxthreeBinding
import client.comm.baoding.ui.vm.SetskxxViewModel

class SetxxThreeFragment : BaseFragment<FragmentSetxxthreeBinding, SetskxxViewModel>() {
    override fun getViewId(): Int {
        return R.layout.fragment_setxxthree
    }

    override fun initViewModel(): SetskxxViewModel = createViewModel()

    override fun initWidget() {
        binding.event = this
        binding.vm = viewModel

        viewModel.callThree.observe(this, {
            it?.let {
                if (it.isSuccess) {
                    toast("成功")
                    requireActivity().finish()
                } else {
//                    toast(it.message)
                }
            }
        })

        binding.emptyLayout.setOnClickListener {
            viewModel.callThree()
        }

        viewModel.dataThree.observe(this, {
            it?.let {
                if (it.isSuccess) {

                    it.data?.pay_list?.let {
                        if (it.size > 0) {
                            viewModel.realNameThree.value = it.get(0).real_name
                            viewModel.nameThree.value = it.get(0).pay_name
                            viewModel.nameChildBank.value = it.get(0).bank_name
                            viewModel.payCardThree.value = it.get(0).pay_card
                        }
                    }

                    binding.emptyLayout.visibility = View.GONE
                } else {
//                    toast(it.message)
                    binding.emptyLayout.errorType = EmptyLayout.NETWORK_ERROR
                }
            }
        })
        viewModel.callThree()
    }

}